package com.haiyangwang1.frames;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CharFrame extends JFrame {
    private JList list;
    private JTextArea area;
    private JTextField txtInput;
    private JButton btn1;
    private JPanel p1,p2;
    public CharFrame(){

        this.setBounds(400,300,500,300);
        list = new JList();
        list.setFixedCellWidth(100);
        list.setFixedCellHeight(30);
        DefaultListModel listModel = new DefaultListModel();
        listModel.addElement("杨琳");
        listModel.addElement("张柳柳");
        listModel.addElement("小范");
        listModel.addElement("李洪伟");
        listModel.addElement("牟丁西");
        listModel.addElement("邓仕卫");
        list.setModel(listModel);
        this.add(list,BorderLayout.WEST);
//        p1.add(area);

        p1 = new JPanel();
        p2 = new JPanel();
        area = new JTextArea();
        txtInput = new JTextField(20);


        p1.setLayout(new BorderLayout());
        p1.add(p2,BorderLayout.SOUTH);
        this.add(p1);
        btn1 = new JButton("发送");
        p1.add(area,BorderLayout.CENTER);
        p2.add(txtInput);
        p2.add(btn1);
        btn1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String txt = txtInput.getText();
                area.setText(area.getText()+txt+"\n");
                txtInput.setText("");
            }
        });
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
